<template>
	<view class="main">
		<!-- 顶部 -->
		<view>
			<view class="top_header">选择城市</view>
			<view class="search">
				<u-search placeholder="搜索城市" @focus="AAA" @search='onchange' @custom='onchange'
					v-model='value'></u-search>
			</view>
		</view>
		<!-- <view class="top_header">当前城市</view> -->
		<!-- <view class="s_button">临沂</view> -->
		<view v-if="show">
			<view v-for="item,index in areas" :key="index">
				<view class="top_headers">
					{{item.areaName}}
				</view>


				<view>
					<view class="item">
						<view class="city_button" v-for="city in item.children" :key="city.areaId">
							<view @click="getAdvisors(city)">{{city.areaName}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else class="father">
			<view v-for="(item,index) in arrone" :key="index" class="searchvalue" @click="getAdvisors(item)">
				{{item.areaName}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getArea
	} from '@/api/system/bank_request.js'
	export default {
		data() {
			return {
				areas: [],
				show: true,
				arrcity: [],
				value: '',
				arrone: [] // 模糊查询数组
			}

		},
		created() {
			this.getBankArea()
		},
		methods: {
			AAA() {
				this.show = false
			},
			close() {
				this.show = false
			},
			getBankArea() {
				getArea().then(res => {
					this.areas = res.data

					let arr = []
					for (let i = 0; i < res.data.length; i++) {
						let item = res.data[i].children
						for (let j = 0; j < item.length; j++) {
							arr.push({
								areaName: item[j].areaName,
								areaId: item[j].areaId
							})
						}
					}
					this.arrcity = arr
				})
			},
			onchange() {
				if (this.value == '' || this.value == null || this.value == undefined) {
					this.show = true
					return
				}
				for (let i = 0; i < this.arrcity.length; i++) {
					if (this.arrcity[i].areaName.includes(this.value)) {
						this.arrone.push(this.arrcity[i])
					}
				}
			},

			getAdvisors(city) {
				this.$tab.navigateTo(`/pages/advisor/advisorMain?areaId=${city.areaId}`)
			}
		}
	}
</script>

<style scoped>
	.father {
		margin: 20rpx 0 0 60rpx;
		display: flex;
	}

	.searchvalue {
		padding: 10px 20px;
		background-color: white;
		border: 1px solid #ccc;
		border-radius: 10rpx;
		/* text-align: center; */
	}

	.item {
		display: flex;
		width: ;
		flex-wrap: wrap;
		margin-left: 36rpx;
	}

	.s_button {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 180rpx;
		min-height: 72rpx;
		margin-top: 10rpx;
		margin-left: 32rpx;
		gap: 0rpx;
		border-radius: 8rpx;
		opacity: 0rpx;
		background: #EFEFEF;
	}

	.city_button {

		display: flex;
		justify-content: center;
		align-items: center;
		padding: 5rpx;
		width: 180rpx;
		min-height: 72rpx;
		margin-top: 10rpx;
		margin-right: 32rpx;
		gap: 0rpx;
		border-radius: 8rpx;
		opacity: 0rpx;
		background: #EFEFEF;
	}

	.top_header {
		font-size: 40rpx;
		font-weight: 500;
		line-height: 48rpx;
		margin-left: 32rpx;
		padding-top: 20rpx;
	}

	.top_headers {
		font-size: 40rpx;
		font-weight: 500;
		line-height: 48rpx;
		margin-left: 32rpx;
		padding-top: 20rpx;
	}

	.main {
		min-height: 100vh;
		background-color: #FFF;
	}




	.search {
		padding-left: 32rpx;
		padding-right: 24rpx;
		padding-top: 18rpx;
	}
</style>